package org.fuxia.im.gui;

import java.awt.Font;
import java.awt.Image;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.UIManager;

import org.fuxia.im.common.ClientContext;

import java.awt.Color;

public class AddedTip extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	/**
	 * Create the frame.
	 */
	public AddedTip(String result, final String[] friend, final int status) {
		setResizable(false);
		setTitle(ClientContext.getLoginUser().getNickName()+"添加好友");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(300, 300, 460, 340);
		
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		ImageIcon icon = new ImageIcon(Thread.currentThread().getContextClassLoader().getResource("images/lifangfang.jpg")) ;
		icon.setImage(icon.getImage().getScaledInstance(108, 108, Image.SCALE_DEFAULT));
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(120, 0, 334, 276);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel successTip = new JLabel(result);
		successTip.setIcon(new ImageIcon(Thread.currentThread().getContextClassLoader().getResource("images/addSuccess.jpg")));
		successTip.setFont(new Font("微软雅黑", Font.PLAIN, 13)) ;
		successTip.setBounds(10, 22, 288, 30);
		panel.add(successTip);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.WHITE);
		panel_1.setBorder(UIManager.getBorder("FormattedTextField.border"));
		panel_1.setBounds(0, 276, 454, 31);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JButton close = new JButton("确认");
		close.setFont(new Font("微软雅黑", Font.PLAIN, 12)) ;
		close.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String[] user = {friend[0],friend[1],friend[2],friend[3],friend[4],friend[5]} ;
				AddFriend add = new AddFriend(558, 407, 300, 100, user, status) ;
				ClientContext.getContext().put("addFriend", add) ;				
				add.setVisible(true) ;
				dispose() ;
			}
		});
		close.setMargin(new Insets(2, 2, 2, 2));
		close.setBounds(390, 4, 60, 23);
		panel_1.add(close);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBackground(Color.WHITE);
		panel_2.setBorder(UIManager.getBorder("FormattedTextField.border"));
		panel_2.setBounds(0, 0, 119, 276);
		contentPane.add(panel_2);
		panel_2.setLayout(null);
		
		JLabel head = new JLabel("");
		head.setIcon(new ImageIcon(Thread.currentThread().getContextClassLoader().getResource(friend[0])));
		head.setBounds(10, 0, 108, 108);
		panel_2.add(head);
		
		JLabel nickname = new JLabel(friend[1]);
		nickname.setFont(new Font("微软雅黑", Font.BOLD, 12)) ;
		nickname.setBounds(10, 120, 99, 15);
		panel_2.add(nickname);
		
		JLabel userCode = new JLabel(friend[2]);
		userCode.setFont(new Font("微软雅黑", Font.BOLD, 12)) ;
		userCode.setBounds(10, 150, 99, 15);
		panel_2.add(userCode);
		
		JLabel sex = new JLabel("性别："+friend[3]);
		sex.setFont(new Font("微软雅黑", Font.PLAIN, 12)) ;
		sex.setBounds(10, 180, 99, 15);
		panel_2.add(sex);
		
		JLabel age = new JLabel("年龄："+friend[4]);
		age.setFont(new Font("微软雅黑", Font.PLAIN, 12)) ;
		age.setBounds(10, 210, 99, 15);
		panel_2.add(age);
		
		JLabel address = new JLabel("所在地："+friend[5]);
		address.setFont(new Font("微软雅黑", Font.PLAIN, 12)) ;
		address.setBounds(10, 240, 99, 15);
		panel_2.add(address);
	}
	
	public JFrame getFrame() {
		return this ;
	}
}
